<?php
session_start( );
?>
<?php
require_once('connections/mysqlDB.php');
require('smarty_connect.php');

$smarty = new smarty_connect;
$dbConn = new mysqli(HOST,USER,PWD,DB);
$dbConn->query("SET NAMES 'utf8'");
// Get email&password from request object 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
//echo $myusername . '/' . $mypassword . '$$$<br>';
/* prepare statement */
if ($stmt = $dbConn->prepare("SELECT email, a.regid, pastoral_staff, user_level, b.rid, a.country, a.cname, a.first_name, a.last_name FROM registrant a, registration b WHERE email = ? and pwd = ?  and a.regid = b.regid order by rid asc limit 1")) {
    $stmt->bind_param('ss', $myusername, $mypassword);
    $stmt->execute(); 
	$stmt->bind_result($col1, $col2, $col3, $col4, $col5, $col6,$col7,$col8,$col9);
	while ($stmt->fetch()) {
	session_register("regid"); 
	session_register("email");
	session_register("pastor");
	session_register("verifyUser");
	session_register("conferenceID");
	session_register("foreign");
	session_register("expire");
	session_register("fullname");
	// pass session object to con_registration.php or other web page.
	$_SESSION['email']=$col1;
	$_SESSION['regid']=$col2;
	$_SESSION['pastor']=$col3;
	$_SESSION['verifyUser']=$col4;
	$_SESSION['rcname']=$col7;
	$_SESSION['rfirst']=$col8;
	$_SESSION['rlast']=$col9;
	
	//$_SESSION['conferenceID']=$_POST['event'];
	$_SESSION['rid']=$col5;
	if($col7<>""){
	$_SESSION['fullname']=$col7;
	} else { $_SESSION['fullname']=trim($_POST['firt_name']). " " . trim($_POST['last_name']); }
	if ($col6 == "USA") $_SESSION['foreign'] = "N"; else $_SESSION['foreign'] = "Y" ;
	$count =1;
	//$stmt->store_result();
	}
}

$stmt->close();
$dbConn->close();
// Mysql_num_row is counting table row
//$count= $stmt->num_rows;
//echo "count: " . $count . "<br>";
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
include("check_reg_stop.php");
 $_SESSION['expire'] = $expire;

header("location:".$_POST['proc']);
}
else {
$smarty->assign('error',"Wrong email or password");
$smarty->display('error.tpl');
}
?>